package org.jeecg.modules.ParameterModule.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.ParameterModule.entity.*;
import org.jeecg.modules.ParameterModule.service.CategoryInfoService;
import org.jeecg.modules.ParameterModule.service.FormalCategoryInfoService;
import org.jeecg.modules.ParameterModule.service.FormalPlateInfoService;
import org.jeecg.modules.ParameterModule.service.TestPlateInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

/**
 * 后台版号配置
 * */
@Api(tags="后台正式版号配置")
@RestController
@RequestMapping("/admin/formalplate")
@Slf4j
public class FormalPlateInfoController {
    @Autowired
    private FormalPlateInfoService plateService;
    @Autowired
    private FormalCategoryInfoService parameterService;
    @Autowired
    private CategoryInfoService testparameterService;
    @Autowired
    private TestPlateInfoService testplateService;

    //测试区版号
    @Autowired
    private TestPlateInfoService banhao_parameterService;

    /**
     * 总后台查询+版号列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/categoryinfoList")
    public Result<?> queryPageList_category(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                            @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                            String queryName, String queryCode,String pingleiName) {
        Page<MlccCategoryInfo> page = new Page<MlccCategoryInfo>(pageNo, pageSize);
        IPage<MlccCategoryInfo> pageList = plateService.query_CategoryPageList(page,queryName,queryCode,pingleiName);
        if(pageList.getRecords().size()>0){
            for (int i=0;i<pageList.getRecords().size();i++){
                List<QiyongListInfo> qiyongListInfo = testplateService.query_UpdatecategoryRecord(pageList.getRecords().get(i).getId().toString(),"1","0");
                if(qiyongListInfo.size()>0){
                    pageList.getRecords().get(i).setQiyongTime(qiyongListInfo.get(0).getCreateTime());
                }else {
                    pageList.getRecords().get(i).setQiyongTime(pageList.getRecords().get(i).getCreateTime());
                }
            }
        }
        return Result.ok(pageList);
    }

    /**
     * 启用草稿件
     * @param
     * @return boolean
     */
    @PostMapping(value = "/right_enable_caogao")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> right_enable_caogao(@RequestBody Map<String,Object> params) {
        String category_id = params.get("category_id").toString();//获取测试版号id
        System.out.println("===" + category_id);
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
//        try {
            if(category_id==null || "".equals(category_id)){
                return Result.error("id不能为空");
            }
            /**正式版号赋值*/
            String zhengshi_categoryId = "",zhengshi_categoryName="";
            //根据品类id查询测试的详情
            MlccCategoryTestInfo testpinglei = testparameterService.select_testcategoryDetail(category_id);
            String category_code = testpinglei.getCategoryCode();
            MlccCategoryInfo panduan_pinglei = parameterService.select_zscategoryDetail(category_code);//根据品类编号查询品类
            if(panduan_pinglei!=null){
//                return Result.error("该版号已经启用过了");
                Long startTs1 = System.currentTimeMillis(); // 当前时间戳
                /**正式品类id下的参数*/
                String formalcategory_id = panduan_pinglei.getId().toString();
                zhengshi_categoryName = panduan_pinglei.getCategoryName();
                zhengshi_categoryId = panduan_pinglei.getId().toString();
                System.out.println("查询到正式版号id=="+formalcategory_id);
                //根据品类id查询定制项
                List<SmalltemplateTestInfo> test_dingzhilist = banhao_parameterService.query_dingzhiBycategoryId(formalcategory_id);
                //根据品类id查询定制项下的参数
                List<MlccCategoryTestInfo> test_canshulist = banhao_parameterService.query_AllcanshuBypingleiId(formalcategory_id);
                //根据品类id查询互斥项
                List<MutexTestInfo> test_huchilist = banhao_parameterService.query_AllhuchiBypingleiId(formalcategory_id);
                //根据品类id查询绣字部位
                List<CategoryLocationTestInfo> test_xuzilist1 = banhao_parameterService.query_Allxiuzi1BypingleiId(formalcategory_id);
                //根据品类id查询绣字颜色
                List<EmbroideredColorTestInfo> test_xuzilist2 = banhao_parameterService.query_AllxiuziColorBypingleiId(formalcategory_id);
                //根据品类id查询绣字图片
                List<EmbroideredFontTestInfo> test_xuzilist3 = banhao_parameterService.query_AllxiuziFontBypingleiId(formalcategory_id);
                //根据品类id查询撞色
                List<ContrastcolorTestInfo> test_zhuangselist = banhao_parameterService.query_AllzhuangseBypingleiId(formalcategory_id);
                //根据品类id查询净体尺寸
                List<BodySizeTestInfo> test_bodysizelist1 = banhao_parameterService.query_AlljingtiBodysizeBypingleiId(formalcategory_id);
                //根据品类id查询返修
                List<CategoryFanxiuTestInfo> test_fanxiulist = banhao_parameterService.query_AllFanxiuBypingleiId(formalcategory_id);
                //根据品类id查询工艺类型
                List<MlccCategoryTestInfo> test_gongyilist = banhao_parameterService.query_AllGongyiBypingleiId(formalcategory_id);
                //根据版号id查询正式的辅料
                List<CategoryMaterialInfo> test_fuliaolist = banhao_parameterService.query_AllfuliaoBypingleiId2(formalcategory_id);
                //根据版号id查询正式的标准码
                List<StandardCodeInfo> test_standcodelist = banhao_parameterService.query_standardCodelist(formalcategory_id,1);

                /**根据测试品类id查询测试数据*/
                //根据品类id查询定制项
                List<SmalltemplateTestInfo> dingzhilist = testparameterService.query_dingzhiBycategoryId(category_id);
                //根据品类id查询定制项下的参数
                List<MlccCategoryTestInfo> canshulist = parameterService.query_AllcanshuBypingleiId(category_id);
                //根据品类id查询互斥项
                List<MutexTestInfo> huchilist = parameterService.query_AllhuchiBypingleiId(category_id);
                //根据品类id查询绣字部位
                List<CategoryLocationTestInfo> xuzilist1 = parameterService.query_Allxiuzi1BypingleiId(category_id);
                //根据品类id查询绣字颜色
                List<EmbroideredColorTestInfo> xuzilist2 = parameterService.query_AllxiuziColorBypingleiId(category_id);
                //根据品类id查询绣字图片
                List<EmbroideredFontTestInfo> xuzilist3 = parameterService.query_AllxiuziFontBypingleiId(category_id);
                //根据品类id查询撞色
                List<ContrastcolorTestInfo> zhuangselist = parameterService.query_AllzhuangseBypingleiId(category_id);
                //根据品类id查询净体尺寸
                List<BodySizeTestInfo> bodysizelist1 = parameterService.query_AlljingtiBodysizeBypingleiId(category_id);
                //根据品类id查询返修
                List<CategoryFanxiuTestInfo> fanxiulist = parameterService.query_AllFanxiuBypingleiId(category_id);
                //根据品类id查询工艺类型
                List<MlccCategoryTestInfo> gongyilist = parameterService.query_AllGongyiBypingleiId(category_id);
                //根据版号id查询测试的辅料
                List<CategoryMaterialInfo> fuliaolist = plateService.query_AllfuliaoBypingleiId(category_id);
                //根据版号id查询测试的标准码
                List<StandardCodeInfo> standcodelist = banhao_parameterService.query_standardCodelist(category_id,2);

                /**循环删除正式的所有参数*/
                if (test_canshulist.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (MlccCategoryTestInfo testobject : test_canshulist) {
                        code = parameterService.delete_dingzhi_canshu(testobject.getId().toString());
                    }
                    System.out.println("删除正式参数==" + code);
                }
                if (test_dingzhilist.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (SmalltemplateTestInfo testobject : test_dingzhilist) {
                        code = parameterService.delete_dingzhi(testobject.getId().toString());
                    }
                    System.out.println("删除定制项==" + code);
                }
                if (test_huchilist.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (MutexTestInfo testobject : test_huchilist) {
                        code = parameterService.delete_huchi(testobject.getId().toString());
                    }
                    System.out.println("删除互斥项==" + code);
                }
                if (test_xuzilist1.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (CategoryLocationTestInfo testobject : test_xuzilist1) {
                        code = parameterService.delete_xiuzi_location(testobject.getId().toString());
                    }
                    System.out.println("删除绣字部位==" + code);
                }
                if (test_xuzilist2.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (EmbroideredColorTestInfo testobject : test_xuzilist2) {
                        code = parameterService.delete_xiuzi_color(testobject.getId().toString());
                    }
                    System.out.println("删除绣字颜色==" + code);
                }
                if (test_xuzilist3.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (EmbroideredFontTestInfo testobject : test_xuzilist3) {
                        code = parameterService.delete_xiuzi_fontImg(testobject.getId().toString());
                    }
                    System.out.println("删除绣字字体图片==" + code);
                }
                if (test_zhuangselist.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (ContrastcolorTestInfo testobject : test_zhuangselist) {
                        code = parameterService.delete_zhuangse(testobject.getId().toString());
                    }
                    System.out.println("删除撞色==" + code);
                }
                if (test_bodysizelist1.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (BodySizeTestInfo testobject : test_bodysizelist1) {
                        code = parameterService.delete_testbodySize(testobject.getId().toString());
                    }
                    System.out.println("删除尺寸==" + code);
                }
                if (test_fanxiulist.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (CategoryFanxiuTestInfo testobject : test_fanxiulist) {
                        code = parameterService.delete_testfanxiuSize(testobject.getId().toString());
                    }
                    System.out.println("删除返修==" + code);
                }
                if (test_gongyilist.size() > 0) {
                    //循环删除
                    int code = 0;
                    for (MlccCategoryTestInfo testobject : test_gongyilist) {
                        code = parameterService.delete_testcategory(testobject.getId().toString());
                    }
                    System.out.println("删除工艺类型==" + code);
                }
                if (test_fuliaolist.size() > 0) {
                    //循环删除正式的辅料
                    int code = 0;
                    for (CategoryMaterialInfo testobject : test_fuliaolist) {
                        code = plateService.delete_plate_libu(testobject.getId().toString());
                    }
                    System.out.println("删除正式的辅料==" + code);
                }
                if (test_standcodelist.size() > 0) {
                    //循环删除正式的标准码
                    int code = 0;
                    for (StandardCodeInfo testobject : test_standcodelist) {
                        code = banhao_parameterService.delete_StandardCode_zhengshi(testobject.getId());
                    }
                    System.out.println("删除正式的标准码==" + code);
                }

                int code2 = 0,code3=0,code4=0,code5=0,code6=0,code7=0,code8=0,code9=0,code10=0,code66=0,code11=0,code67=0,code666=0;
                if(dingzhilist.size()>0){
                    for (int i=0;i<dingzhilist.size();i++){
                        //循环添加定制项
                        SmalltemplateTestInfo datainfo = new SmalltemplateTestInfo();
                        datainfo.setModuleId(dingzhilist.get(i).getModuleId());
                        datainfo.setCategoryId(formalcategory_id);
                        datainfo.setCode(dingzhilist.get(i).getCode());
                        datainfo.setParameter(dingzhilist.get(i).getParameter());
                        datainfo.setImgs(dingzhilist.get(i).getImgs());
                        datainfo.setNumbers(dingzhilist.get(i).getNumbers());
                        datainfo.setIstype(dingzhilist.get(i).getIstype());
                        datainfo.setRemark(dingzhilist.get(i).getRemark());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code2 = parameterService.add_dingzhi(datainfo);
                    }
                }

                if(canshulist.size()>0){
                    for (int i=0;i<canshulist.size();i++){
                        String praent_id = "";
                        SmalltemplateTestInfo ceshidingdatainfo = testparameterService.query_dingzhiBydingzhId(canshulist.get(i).getParentId());
                        if(ceshidingdatainfo!=null){
                            //查询新增的定制项
                            List<SmalltemplateTestInfo> zsdingzhi_datalist = parameterService.query_dingzhiBycategoryId(formalcategory_id);
                            if(zsdingzhi_datalist.size()>0){
                                for (int k=0;k<zsdingzhi_datalist.size();k++){
                                    if(ceshidingdatainfo.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                        praent_id = zsdingzhi_datalist.get(k).getId().toString();
                                    }
                                }
                            }
                        }
                        //循环添加定制项下的参数
                        MlccCategoryTestInfo datainfo = new MlccCategoryTestInfo();
                        datainfo.setCategoryName(canshulist.get(i).getCategoryName());
                        datainfo.setCategoryCode(canshulist.get(i).getCategoryCode());
                        datainfo.setParentId(praent_id);//正式的上级id
                        datainfo.setImg(canshulist.get(i).getImg());
                        datainfo.setTopid(formalcategory_id);
                        datainfo.setNumbers(canshulist.get(i).getNumbers());
                        datainfo.setIsType(canshulist.get(i).getIsType());
                        datainfo.setCost(canshulist.get(i).getCost());
                        datainfo.setTeamPrice2(canshulist.get(i).getTeamPrice2());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code3 = parameterService.add_dingzhi_canshu(datainfo);
                    }
                }
                if(xuzilist1.size()>0){
                    for (int i=0;i<xuzilist1.size();i++){
                        //循环添加绣字部位
                        CategoryLocationTestInfo datainfo = new CategoryLocationTestInfo();
                        datainfo.setCode(xuzilist1.get(i).getCode());
                        datainfo.setXiuziLocaltion(xuzilist1.get(i).getXiuziLocaltion());
                        datainfo.setCategoryId(formalcategory_id);
                        datainfo.setRemark(xuzilist1.get(i).getRemark());
                        datainfo.setNumbers(xuzilist1.get(i).getNumbers());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code5 = parameterService.add_xiuzi_location(datainfo);
                    }
                }
                if(xuzilist2.size()>0){
                    for (int i=0;i<xuzilist2.size();i++){
                        //循环添加绣字颜色
                        EmbroideredColorTestInfo datainfo = new EmbroideredColorTestInfo();
                        datainfo.setCode(xuzilist2.get(i).getCode());
                        datainfo.setColorName(xuzilist2.get(i).getColorName());
                        datainfo.setCategoryId(formalcategory_id);
                        datainfo.setColorImg(xuzilist2.get(i).getColorImg());
                        datainfo.setRemark(xuzilist2.get(i).getRemark());
                        datainfo.setNumbers(xuzilist2.get(i).getNumbers());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code6 = parameterService.add_xiuzi_color(datainfo);
                    }
                }
                if(xuzilist3.size()>0){
                    for (int i=0;i<xuzilist3.size();i++){
                        //循环添加绣字字体
                        EmbroideredFontTestInfo datainfo = new EmbroideredFontTestInfo();
                        datainfo.setCode(xuzilist3.get(i).getCode());
                        datainfo.setEmbroideredName(xuzilist3.get(i).getEmbroideredName());
                        datainfo.setCategoryId(formalcategory_id);
                        datainfo.setEmbroideredImage(xuzilist3.get(i).getEmbroideredImage());
                        datainfo.setRemark(xuzilist3.get(i).getRemark());
                        datainfo.setNumbers(xuzilist3.get(i).getNumbers());
                        datainfo.setIsZitiImg(xuzilist3.get(i).getIsZitiImg());
                        datainfo.setXiuziSize(xuzilist3.get(i).getXiuziSize());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code66 = parameterService.add_xiuzi_fontImg(datainfo);
                    }
                }

                if(zhuangselist.size()>0){
                    for (int i=0;i<zhuangselist.size();i++){
                        //循环添加撞色
                        ContrastcolorTestInfo datainfo = new ContrastcolorTestInfo();
                        datainfo.setTopId(formalcategory_id);
                        datainfo.setCode(zhuangselist.get(i).getCode());
                        datainfo.setContrastColorName(zhuangselist.get(i).getContrastColorName());
                        datainfo.setCategoryId(zhuangselist.get(i).getCategoryId());
                        datainfo.setContrastColorImg(zhuangselist.get(i).getContrastColorImg());
                        datainfo.setDingzhiId(zhuangselist.get(i).getDingzhiId());
                        datainfo.setRemark(zhuangselist.get(i).getRemark());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code7 = parameterService.add_zhuangse(datainfo);
                    }
                }
                if(bodysizelist1.size()>0){
                    for (int i=0;i<bodysizelist1.size();i++){
                        //循环添加身体尺寸
                        BodySizeTestInfo datainfo = new BodySizeTestInfo();
                        datainfo.setBodySizename(bodysizelist1.get(i).getBodySizename());
                        datainfo.setUnit(bodysizelist1.get(i).getUnit());
                        datainfo.setModuleId(bodysizelist1.get(i).getModuleId());
                        datainfo.setCategoryId(formalcategory_id);
                        datainfo.setNumbers(bodysizelist1.get(i).getNumbers());
                        datainfo.setIsJin(bodysizelist1.get(i).getIsJin());
                        datainfo.setMax(bodysizelist1.get(i).getMax());
                        datainfo.setMin(bodysizelist1.get(i).getMin());
                        datainfo.setIsBitian(bodysizelist1.get(i).getIsBitian());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code8 = parameterService.add_testbodySize(datainfo);
                    }
                }
                if(fanxiulist.size()>0){
                    for (int i=0;i<fanxiulist.size();i++){
                        //循环添加返修
                        CategoryFanxiuTestInfo datainfo = new CategoryFanxiuTestInfo();
                        datainfo.setBodySizename(fanxiulist.get(i).getBodySizename());
                        datainfo.setUnit(fanxiulist.get(i).getUnit());
                        datainfo.setCategoryId(formalcategory_id);
                        datainfo.setNumbers(fanxiulist.get(i).getNumbers());
                        datainfo.setMax(fanxiulist.get(i).getMax());
                        datainfo.setMin(fanxiulist.get(i).getMin());
                        datainfo.setRemark(fanxiulist.get(i).getRemark());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code9 = parameterService.add_testFanxiuSize(datainfo);
                    }
                }
                if(gongyilist.size()>0){
                    for (int i=0;i<gongyilist.size();i++){
                        //循环添加工艺
                        MlccCategoryTestInfo datainfo = new MlccCategoryTestInfo();
//                        MlccCategoryInfo gongyidetail = parameterService.select_canshu_gongyiDetailById(gongyilist.get(i).getCategoryCode(),
//                                gongyilist.get(i).getCategoryName(),formalcategory_id,4);//根据品类编号查询品类
//                        if(gongyidetail==null || "".equals(gongyidetail)){
                            System.out.println("进来判断这个添加工艺了吗===");
                            datainfo.setCategoryCode(gongyilist.get(i).getCategoryCode());
                            datainfo.setCategoryName(gongyilist.get(i).getCategoryName());
                            datainfo.setParentId(gongyilist.get(i).getParentId());
                            datainfo.setImg(gongyilist.get(i).getImg());
                            datainfo.setRemark(gongyilist.get(i).getRemark());
                            datainfo.setTopid(formalcategory_id);
                            datainfo.setIsType(4);
                            datainfo.setCategorySex(gongyilist.get(i).getCategorySex());
                            datainfo.setNumbers(gongyilist.get(i).getNumbers());
                            datainfo.setSysOrgCode(sys_org_code);
                            datainfo.setCreateBy(create_by);
                            code10 = parameterService.add_category_pinglei2(datainfo);
//                        }else {
//                            System.out.println("不是空的添加工艺了=="+"===cde==="+code10+"==="+gongyidetail.getId().toString());
//                        }
                    }
                }
                if(huchilist.size()>0){
                    for (int i=0;i<huchilist.size();i++){
                        //循环添加互斥
//                        MutexTestInfo datainfo = new MutexTestInfo();
//                        datainfo.setMutexName(huchilist.get(i).getMutexName());
//                        datainfo.setTopId(formalcategory_id);
//                        datainfo.setCategoryId(huchilist.get(i).getCategoryId());
//                        datainfo.setCategoryOther(huchilist.get(i).getCategoryOther());
//                        datainfo.setMutexReason(huchilist.get(i).getMutexReason());
//                        datainfo.setStatus(huchilist.get(i).getStatus());
//                        datainfo.setCode(huchilist.get(i).getCode());
//                        datainfo.setDingzhi1(huchilist.get(i).getDingzhi1());
//                        datainfo.setDingzhi2(huchilist.get(i).getDingzhi2());
//                        datainfo.setSysOrgCode(sys_org_code);
//                        datainfo.setCreateBy(create_by);
//                        code4 = parameterService.add_huchi(datainfo);
                        String dingzhi1="",dingzhi2="";
                        String firstId = "",secoundId="";
                        List<SmalltemplateTestInfo> zsdingzhi_datalist = parameterService.query_dingzhiBycategoryId(formalcategory_id);
                        SmalltemplateTestInfo ceshidingdatainfo1 = testparameterService.query_dingzhiBydingzhId(huchilist.get(i).getDingzhi1());
                        SmalltemplateTestInfo ceshidingdatainfo2 = testparameterService.query_dingzhiBydingzhId(huchilist.get(i).getDingzhi2());
                        if(ceshidingdatainfo1!=null){
                            if(zsdingzhi_datalist.size()>0){
                                for (int k=0;k<zsdingzhi_datalist.size();k++){
                                    if(ceshidingdatainfo1.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                        dingzhi1 = zsdingzhi_datalist.get(k).getId().toString();
                                        break;
                                    }
                                }
                            }
                        }
                        if(ceshidingdatainfo2!=null){
                            if(zsdingzhi_datalist.size()>0){
                                for (int k=0;k<zsdingzhi_datalist.size();k++){
                                    if(ceshidingdatainfo2.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                        dingzhi2 = zsdingzhi_datalist.get(k).getId().toString();
                                        break;
                                    }
                                }
                            }
                        }
                        //根据类别id查询类别详情
                        MlccCategoryTestInfo leibiedatainfo1 = testparameterService.select_testcategoryDetail(huchilist.get(i).getCategoryId());
                        if(leibiedatainfo1!=null){
                            MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo1.getCategoryCode(),formalcategory_id,dingzhi1);
                            if(zsleibie!=null){
                                firstId = zsleibie.getId().toString();
                            }
                        }
                        String canshuids[] = huchilist.get(i).getCategoryOther().split(",");
                        String strbody="";
                        for (String s:canshuids){
                            //根据类别id查询类别详情
                            MlccCategoryTestInfo leibiedatainfo2 = testparameterService.select_testcategoryDetail(s);
                            if(leibiedatainfo2!=null){
                                MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo2.getCategoryCode(),formalcategory_id,dingzhi2);
                                if(zsleibie!=null){
                                    strbody += zsleibie.getId().toString()+",";
                                }
                            }
                        }
                        if(strbody!=null || !"".equals(strbody)){
                            secoundId = strbody.substring(0,strbody.length()-1);
                        }
                        //循环添加互斥
                        MutexTestInfo datainfo = new MutexTestInfo();
                        datainfo.setMutexName(huchilist.get(i).getMutexName());
                        datainfo.setTopId(formalcategory_id);
                        datainfo.setCategoryId(firstId);
                        datainfo.setCategoryOther(secoundId);
                        datainfo.setMutexReason(huchilist.get(i).getMutexReason());
                        datainfo.setStatus(huchilist.get(i).getStatus());
                        datainfo.setCode(huchilist.get(i).getCode());
                        datainfo.setDingzhi1(dingzhi1);
                        datainfo.setDingzhi2(dingzhi2);
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code4 = parameterService.add_huchi(datainfo);
                    }
                }
                if(fuliaolist.size()>0){
                    for (int i=0;i<fuliaolist.size();i++){
                        //循环添加辅料项--正式
                        CategoryMaterialInfo datainfo = new CategoryMaterialInfo();
                        datainfo.setOtherId(fuliaolist.get(i).getOtherId());
                        datainfo.setCategoryId(formalcategory_id);
                        datainfo.setIsLibu(fuliaolist.get(i).getIsLibu());
                        datainfo.setRemark(fuliaolist.get(i).getRemark());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code666 = plateService.add_plate_libu(datainfo);
                    }
                }
                if(standcodelist.size()>0){
                    for (int i=0;i<standcodelist.size();i++){
                        //循环添加标准码项--正式
                        StandardCodeInfo datainfo = new StandardCodeInfo();
                        String codefanxiu = UUID.randomUUID().toString().substring(0,12);
                        //8位随机数
                        int random=new Random().nextInt(100000)+1;//为变量赋随机值1-99999999;
                        String standcodeId = codefanxiu+random+i;
                        datainfo.setId(standcodeId);
                        datainfo.setCategoryId(formalcategory_id);
                        datainfo.setStandardName(standcodelist.get(i).getStandardName());
                        datainfo.setCode(standcodelist.get(i).getCode());
                        datainfo.setNumbers(standcodelist.get(i).getNumbers());
                        datainfo.setRemark(standcodelist.get(i).getRemark());
                        datainfo.setSysOrgCode(sys_org_code);
                        datainfo.setCreateBy(create_by);
                        code666 = banhao_parameterService.add_StandardCode_zhengshi(datainfo);
                    }
                }
                Long startTs2 = System.currentTimeMillis(); // 当前时间戳
                System.out.println("输出时间========"+(startTs2-startTs1));
                System.out.println("各个code=="+code2+"="+code3+"="+code4+"="+code5+"="+code6+"="+code66+"="+code7+"="+code8+"="+code9+"="+code10+"==67=="+code67);
                if(code2>0 || code3>0 || code4>0 || code5>0 || code6>0 || code66>0 || code67>0 || code7>0 || code8>0 || code9>0 || code10>0 || code11>0 || code666>0){
                    //测试区
                    parameterService.add_qiyong_record(category_id,"0","0",zhengshi_categoryName+" 【再次】 启用成为正式版号",create_by,sys_org_code);
                    //正式插入记录
                    parameterService.add_qiyong_record(formalcategory_id,"0","0","已由草稿件"+zhengshi_categoryName+" 【再次】 启用成为正式版号",create_by,sys_org_code);
                    return Result.ok("再次启用成功");
                }else {
                    return Result.error("启用失败");
                }
            }else {
                //赋值测试类别id
                testpinglei.setTestcategoryId(testpinglei.getId().toString());
                int code1 = parameterService.add_category_pinglei2(testpinglei);
                //拿到关联版号的品类id
                String pinglei_id = testpinglei.getTopid();
                System.out.println("chengogn2===="+code1+"====事办好="+testpinglei.getIsType());
                int code2 = 0,code3=0,code4=0,code5=0,code6=0,code7=0,code8=0,code9=0,code10=0,code66=0,code666=0;
                if(code1>0){
                    /**根据测试版号id查询的测试项*/
                    //根据品类id查询定制项
                    List<SmalltemplateTestInfo> dingzhilist = testparameterService.query_dingzhiBycategoryId(category_id);
                    //根据品类id查询定制项下的参数
                    List<MlccCategoryTestInfo> canshulist = parameterService.query_AllcanshuBypingleiId(category_id);
                    //根据品类id查询互斥项
                    List<MutexTestInfo> huchilist = parameterService.query_AllhuchiBypingleiId(category_id);
                    //根据品类id查询绣字部位
                    List<CategoryLocationTestInfo> xuzilist1 = parameterService.query_Allxiuzi1BypingleiId(category_id);
                    //根据品类id查询绣字颜色
                    List<EmbroideredColorTestInfo> xuzilist2 = parameterService.query_AllxiuziColorBypingleiId(category_id);
                    //根据品类id查询绣字图片
                    List<EmbroideredFontTestInfo> xuzilist3 = parameterService.query_AllxiuziFontBypingleiId(category_id);
                    //根据品类id查询撞色
                    List<ContrastcolorTestInfo> zhuangselist = parameterService.query_AllzhuangseBypingleiId(category_id);
                    //根据品类id查询净体尺寸
                    List<BodySizeTestInfo> bodysizelist1 = parameterService.query_AlljingtiBodysizeBypingleiId(category_id);
                    //根据品类id查询返修
                    List<CategoryFanxiuTestInfo> fanxiulist = parameterService.query_AllFanxiuBypingleiId(category_id);
                    //根据品类id查询工艺类型
                    List<MlccCategoryTestInfo> gongyilist = parameterService.query_AllGongyiBypingleiId(category_id);
                    //根据版号id查询测试的辅料
                    List<CategoryMaterialInfo> fuliaolist = plateService.query_AllfuliaoBypingleiId(category_id);
                    //根据版号id查询测试的标准码
                    List<StandardCodeInfo> standcodelist = banhao_parameterService.query_standardCodelist(category_id,2);
                    MlccCategoryInfo pingleiDetail = parameterService.select_zscategoryDetail(category_code);//根据品类编号查询品类
                    if(pingleiDetail!=null){
                        String zspingleiId = pingleiDetail.getId().toString();//正式版号id
                        zhengshi_categoryId = pingleiDetail.getId().toString();//正式版号id
                        zhengshi_categoryName = pingleiDetail.getCategoryName();
                        //根据品类id修改加价的版号
//                        plateService.update_price_pinglei(pinglei_id,zhengshi_categoryId);
                        if(fuliaolist.size()>0){
                            for (int i=0;i<fuliaolist.size();i++){
                                //循环添加辅料项--正式
                                CategoryMaterialInfo datainfo = new CategoryMaterialInfo();
                                datainfo.setOtherId(fuliaolist.get(i).getOtherId());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setIsLibu(fuliaolist.get(i).getIsLibu());
                                datainfo.setRemark(fuliaolist.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code666 = plateService.add_plate_libu(datainfo);
                            }
                        }
                        if(dingzhilist.size()>0){
                            for (int i=0;i<dingzhilist.size();i++){
                                //循环添加定制项
                                SmalltemplateTestInfo datainfo = new SmalltemplateTestInfo();
                                datainfo.setModuleId(dingzhilist.get(i).getModuleId());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setCode(dingzhilist.get(i).getCode());
                                datainfo.setParameter(dingzhilist.get(i).getParameter());
                                datainfo.setImgs(dingzhilist.get(i).getImgs());
                                datainfo.setNumbers(dingzhilist.get(i).getNumbers());
                                datainfo.setIstype(dingzhilist.get(i).getIstype());
                                datainfo.setRemark(dingzhilist.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code2 = parameterService.add_dingzhi(datainfo);
                            }
                        }
                        if(canshulist.size()>0){
                            for (int i=0;i<canshulist.size();i++){
                                //循环添加定制项下的参数
                                String praent_id = "";
                                SmalltemplateTestInfo ceshidingdatainfo = testparameterService.query_dingzhiBydingzhId(canshulist.get(i).getParentId());
                                if(ceshidingdatainfo!=null){
                                    //查询新增的定制项
                                    List<SmalltemplateTestInfo> zsdingzhi_datalist = parameterService.query_dingzhiBycategoryId(zspingleiId);
                                    if(zsdingzhi_datalist.size()>0){
                                        for (int k=0;k<zsdingzhi_datalist.size();k++){
                                            if(ceshidingdatainfo.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                                praent_id = zsdingzhi_datalist.get(k).getId().toString();
                                            }
                                        }
                                    }
                                }
                                MlccCategoryTestInfo datainfo = new MlccCategoryTestInfo();
                                datainfo.setCategoryName(canshulist.get(i).getCategoryName());
                                datainfo.setCategoryCode(canshulist.get(i).getCategoryCode());
                                datainfo.setParentId(praent_id);
                                datainfo.setImg(canshulist.get(i).getImg());
                                datainfo.setTopid(zspingleiId);
                                datainfo.setNumbers(canshulist.get(i).getNumbers());
                                datainfo.setIsType(canshulist.get(i).getIsType());
                                datainfo.setCost(canshulist.get(i).getCost());
                                datainfo.setTeamPrice2(canshulist.get(i).getTeamPrice2());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code3 = parameterService.add_dingzhi_canshu(datainfo);
                            }
                        }
                        if(huchilist.size()>0){
                            for (int i=0;i<huchilist.size();i++){
                                //循环添加互斥
//                                MutexTestInfo datainfo = new MutexTestInfo();
//                                datainfo.setMutexName(huchilist.get(i).getMutexName());
//                                datainfo.setTopId(zspingleiId);
//                                datainfo.setCategoryId(huchilist.get(i).getCategoryId());
//                                datainfo.setCategoryOther(huchilist.get(i).getCategoryOther());
//                                datainfo.setMutexReason(huchilist.get(i).getMutexReason());
//                                datainfo.setStatus(huchilist.get(i).getStatus());
//                                datainfo.setCode(huchilist.get(i).getCode());
//                                datainfo.setDingzhi1(huchilist.get(i).getDingzhi1());
//                                datainfo.setDingzhi2(huchilist.get(i).getDingzhi2());
//                                datainfo.setSysOrgCode(sys_org_code);
//                                datainfo.setCreateBy(create_by);
//                                code4 = parameterService.add_huchi(datainfo);

                                //查询新增的定制项
                                String dingzhi1="",dingzhi2="";
                                String firstId = "",secoundId="";
                                List<SmalltemplateTestInfo> zsdingzhi_datalist = parameterService.query_dingzhiBycategoryId(zspingleiId);
                                SmalltemplateTestInfo ceshidingdatainfo1 = testparameterService.query_dingzhiBydingzhId(huchilist.get(i).getDingzhi1());
                                SmalltemplateTestInfo ceshidingdatainfo2 = testparameterService.query_dingzhiBydingzhId(huchilist.get(i).getDingzhi2());
                                if(ceshidingdatainfo1!=null){
                                    if(zsdingzhi_datalist.size()>0){
                                        for (int k=0;k<zsdingzhi_datalist.size();k++){
                                            if(ceshidingdatainfo1.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                                dingzhi1 = zsdingzhi_datalist.get(k).getId().toString();
                                                break;
                                            }
                                        }
                                    }
                                }
                                if(ceshidingdatainfo2!=null){
                                    if(zsdingzhi_datalist.size()>0){
                                        for (int k=0;k<zsdingzhi_datalist.size();k++){
                                            if(ceshidingdatainfo2.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                                dingzhi2 = zsdingzhi_datalist.get(k).getId().toString();
                                                break;
                                            }
                                        }
                                    }
                                }
                                //根据类别id查询类别详情
                                MlccCategoryTestInfo leibiedatainfo1 = testparameterService.select_testcategoryDetail(huchilist.get(i).getCategoryId());
                                if(leibiedatainfo1!=null){
                                    MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo1.getCategoryCode(),zspingleiId,dingzhi1);
                                    if(zsleibie!=null){
                                        firstId = zsleibie.getId().toString();
                                    }
                                }
                                String canshuids[] = huchilist.get(i).getCategoryOther().split(",");
                                String strbody="";
                                for (String s:canshuids){
                                    //根据类别id查询类别详情
                                    MlccCategoryTestInfo leibiedatainfo2 = testparameterService.select_testcategoryDetail(s);
                                    if(leibiedatainfo2!=null){
                                        MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo2.getCategoryCode(),zspingleiId,dingzhi2);
                                        if(zsleibie!=null){
                                            strbody += zsleibie.getId().toString()+",";
                                        }
                                    }
                                }
                                if(strbody!=null || !"".equals(strbody)){
                                    secoundId = strbody.substring(0,strbody.length()-1);
                                }
                                //循环添加互斥
                                MutexTestInfo datainfo = new MutexTestInfo();
                                datainfo.setMutexName(huchilist.get(i).getMutexName());
                                datainfo.setTopId(zspingleiId);
                                datainfo.setCategoryId(firstId);
                                datainfo.setCategoryOther(secoundId);
                                datainfo.setMutexReason(huchilist.get(i).getMutexReason());
                                datainfo.setStatus(huchilist.get(i).getStatus());
                                datainfo.setCode(huchilist.get(i).getCode());
                                datainfo.setDingzhi1(dingzhi1);
                                datainfo.setDingzhi2(dingzhi2);
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code4 = parameterService.add_huchi(datainfo);
                            }
                        }
                        if(xuzilist1.size()>0){
                            for (int i=0;i<xuzilist1.size();i++){
                                //循环添加绣字部位
                                CategoryLocationTestInfo datainfo = new CategoryLocationTestInfo();
                                datainfo.setCode(xuzilist1.get(i).getCode());
                                datainfo.setXiuziLocaltion(xuzilist1.get(i).getXiuziLocaltion());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setSinglePrice2(xuzilist1.get(i).getSinglePrice2());
                                datainfo.setTeamPrice2(xuzilist1.get(i).getTeamPrice2());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code5 = parameterService.add_xiuzi_location(datainfo);
                            }
                        }
                        if(xuzilist2.size()>0){
                            for (int i=0;i<xuzilist2.size();i++){
                                //循环添加绣字颜色
                                EmbroideredColorTestInfo datainfo = new EmbroideredColorTestInfo();
                                datainfo.setCode(xuzilist2.get(i).getCode());
                                datainfo.setColorName(xuzilist2.get(i).getColorName());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setColorImg(xuzilist2.get(i).getColorImg());
                                datainfo.setSinglePrice2(xuzilist2.get(i).getSinglePrice2());
                                datainfo.setTeamPrice2(xuzilist2.get(i).getTeamPrice2());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code6 = parameterService.add_xiuzi_color(datainfo);
                            }
                        }
                        if(xuzilist3.size()>0){
                            for (int i=0;i<xuzilist3.size();i++){
                                //循环添加绣字字体
                                EmbroideredFontTestInfo datainfo = new EmbroideredFontTestInfo();
                                datainfo.setCode(xuzilist3.get(i).getCode());
                                datainfo.setEmbroideredName(xuzilist3.get(i).getEmbroideredName());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setEmbroideredImage(xuzilist3.get(i).getEmbroideredImage());
                                datainfo.setSinglePrice2(xuzilist3.get(i).getSinglePrice2());
                                datainfo.setTeamPrice2(xuzilist3.get(i).getTeamPrice2());
                                datainfo.setIsZitiImg(xuzilist3.get(i).getIsZitiImg());
                                datainfo.setXiuziSize(xuzilist3.get(i).getXiuziSize());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code66 = parameterService.add_xiuzi_fontImg(datainfo);
                            }
                        }
                        if(zhuangselist.size()>0){
                            for (int i=0;i<zhuangselist.size();i++){
                                //循环添加撞色
                                ContrastcolorTestInfo datainfo = new ContrastcolorTestInfo();
                                datainfo.setTopId(zspingleiId);
                                datainfo.setCode(zhuangselist.get(i).getCode());
                                datainfo.setContrastColorName(zhuangselist.get(i).getContrastColorName());
                                datainfo.setCategoryId(zhuangselist.get(i).getCategoryId());
                                datainfo.setContrastColorImg(zhuangselist.get(i).getContrastColorImg());
                                datainfo.setSinglePrice2(zhuangselist.get(i).getSinglePrice2());
                                datainfo.setTeamPrice2(zhuangselist.get(i).getTeamPrice2());
                                datainfo.setDingzhiId(zhuangselist.get(i).getDingzhiId());
                                datainfo.setRemark(zhuangselist.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code7 = parameterService.add_zhuangse(datainfo);
                            }
                        }
                        if(bodysizelist1.size()>0){
                            for (int i=0;i<bodysizelist1.size();i++){
                                //循环添加身体尺寸
                                BodySizeTestInfo datainfo = new BodySizeTestInfo();
                                datainfo.setBodySizename(bodysizelist1.get(i).getBodySizename());
                                datainfo.setUnit(bodysizelist1.get(i).getUnit());
                                datainfo.setModuleId(bodysizelist1.get(i).getModuleId());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setNumbers(bodysizelist1.get(i).getNumbers());
                                datainfo.setIsJin(bodysizelist1.get(i).getIsJin());
                                datainfo.setMax(bodysizelist1.get(i).getMax());
                                datainfo.setMin(bodysizelist1.get(i).getMin());
                                datainfo.setIsBitian(bodysizelist1.get(i).getIsBitian());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code8 = parameterService.add_testbodySize(datainfo);
                            }
                        }
                        if(fanxiulist.size()>0){
                            for (int i=0;i<fanxiulist.size();i++){
                                //循环添加返修
                                CategoryFanxiuTestInfo datainfo = new CategoryFanxiuTestInfo();
                                datainfo.setBodySizename(fanxiulist.get(i).getBodySizename());
                                datainfo.setUnit(fanxiulist.get(i).getUnit());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setNumbers(fanxiulist.get(i).getNumbers());
                                datainfo.setMax(fanxiulist.get(i).getMax());
                                datainfo.setMin(fanxiulist.get(i).getMin());
                                datainfo.setRemark(fanxiulist.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code9 = parameterService.add_testFanxiuSize(datainfo);
                            }
                        }
                        if(gongyilist.size()>0){
                            for (int i=0;i<gongyilist.size();i++){
                                //循环添加工艺
                                MlccCategoryTestInfo datainfo = new MlccCategoryTestInfo();
                                datainfo.setCategoryCode(gongyilist.get(i).getCategoryCode());
                                datainfo.setCategoryName(gongyilist.get(i).getCategoryName());
                                datainfo.setParentId(gongyilist.get(i).getParentId());
                                datainfo.setImg(gongyilist.get(i).getImg());
                                datainfo.setRemark(gongyilist.get(i).getRemark());
                                datainfo.setTopid(zspingleiId);
                                datainfo.setIsType(4);
                                datainfo.setCategorySex(gongyilist.get(i).getCategorySex());
                                datainfo.setNumbers(gongyilist.get(i).getNumbers());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code10 = parameterService.add_category_pinglei2(datainfo);
                            }
                        }
                        if(standcodelist.size()>0){
                            for (int i=0;i<standcodelist.size();i++){
                                //循环添加标准码项--正式
                                StandardCodeInfo datainfo = new StandardCodeInfo();
                                String codefanxiu = UUID.randomUUID().toString().substring(0,12);
                                //8位随机数
                                int random=new Random().nextInt(100000)+1;//为变量赋随机值1-99999999;
                                String standcodeId = codefanxiu+random+i;
                                datainfo.setId(standcodeId);
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setStandardName(standcodelist.get(i).getStandardName());
                                datainfo.setCode(standcodelist.get(i).getCode());
                                datainfo.setNumbers(standcodelist.get(i).getNumbers());
                                datainfo.setRemark(standcodelist.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code666 = banhao_parameterService.add_StandardCode_zhengshi(datainfo);
                            }
                        }
                    }
                    System.out.println("各个code=="+code2+"="+code3+"="+code4+"="+code5+"="+code6+"="+code66+"="+code7+"="+code8+"="+code9+"="+code10+"=="+code666);
                    if(code2>0 || code3>0 || code4>0 || code5>0 || code6>0 || code66>0 || code7>0 || code8>0 || code9>0 || code10>0 || code666>0){
                        //测试区
                        parameterService.add_qiyong_record(category_id,"1","0",zhengshi_categoryName+"正式启用成为正式版号",create_by,sys_org_code);
                        //正式插入记录
                        parameterService.add_qiyong_record(zhengshi_categoryId,"1","0","已由草稿件"+zhengshi_categoryName+"正式启用成为正式版号",create_by,sys_org_code);
                        return Result.ok("启用成功");
                    }else {
                        return Result.error("启用失败");
                    }
                }else {
                    return Result.error("启用失败");
                }
            }
//        }catch (Exception e){
//            return Result.error("失败，参数错误");
//        }
    }

    /**
     * 总后台查询+版号下的辅料-里布
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/categoryinfo_material_libu")
    public Result<?> categoryinfo_material_libu(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                            @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                            String queryName, String queryCode,String category_id) {
        Page<CategoryMaterialInfo> page = new Page<CategoryMaterialInfo>(pageNo, pageSize);
        IPage<CategoryMaterialInfo> pageList = plateService.query_material_libuPageList(page,category_id,queryName,queryCode);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+版号下的辅料-低领里
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/categoryinfo_material_dilingli")
    public Result<?> categoryinfo_material_dilingli(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                String queryName, String queryCode,String category_id) {
        Page<CategoryMaterialInfo> page = new Page<CategoryMaterialInfo>(pageNo, pageSize);
        IPage<CategoryMaterialInfo> pageList = plateService.query_material_dilingliPageList(page,category_id,queryName,queryCode);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+版号下的辅料-纽扣
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/categoryinfo_material_buttons")
    public Result<?> categoryinfo_material_buttons(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                String queryName, String queryCode,String category_id) {
        Page<CategoryMaterialInfo> page = new Page<CategoryMaterialInfo>(pageNo, pageSize);
        IPage<CategoryMaterialInfo> pageList = plateService.query_material_buttonsPageList(page,category_id,queryName,queryCode);
        return Result.ok(pageList);
    }

    /**
     * 查询所有的里布/底领尼/纽扣
     * @return
     */
    @GetMapping(value = "/query_all_materialInfo")
    public Result<?> query_all_materialInfo(@RequestParam(name="type")int type){
        List<CategoryMaterialInfo> datalist = plateService.query_all_materialInfo(type);
        if(datalist.size()>0){
            return Result.ok(datalist);
        }else{
            return Result.error("未找到对应数据");
        }
    }

    /**
     * 配置版号下的辅料
     * @param
     * @return boolean
     */
    @PostMapping(value = "/set_plate_material")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> set_plate_material(@RequestBody CategoryMaterialInfo testInfo) {
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = plateService.add_plate_libu(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 删除计量局
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_plate_material")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_plate_material(@RequestBody Map<String,Object> params) {
        String material_id = params.get("material_id").toString();
        System.out.println("===" + material_id);
        if(material_id==null || "".equals(material_id)){
            return Result.error("辅料id不能为空");
        }
        try {
            int code = plateService.delete_plate_libu(material_id);
            if(code>0){
                return Result.ok("移除成功");
            }else {
                return Result.error("移除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

}
